<template>
	<view>
		<view class="c-box fl alc">
			<u-avatar :src="$http+user.avatar" ></u-avatar>
			<view class="ml32">
				<h3 v-if="user.userName">{{user.userName}}</h3>
				<h3 @click="tologin" v-else>请先登录|注册</h3>
			</view>
		</view>
		
		<view class="c-box mt100">
			<u-cell-group :border="false">
				<u-cell :title="item.title" :icon="item.icon" v-for="item in info" :key="item.title" :url="item.url"></u-cell>
			</u-cell-group>
		</view>
		<view class="c-box-nobg mt100" v-if="user.userName">
			<u-button type="primary" text="退出登录" plain @click="laout"></u-button>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import { getUserInfoAPI } from '../../api/member';
import { onShow} from '@dcloudio/uni-app'
	const info =ref([
		{
			title:'个人信息',
			icon:"edit-pen",
			url:'/subpages/user/userInfo/userInfo'
		},{
			title:'修改密码',
			icon:"lock",
			url:'/subpages/user/update/update'
		},{
			title:'意见反馈',
			icon:"error",
			url:'/subpages/user/feedback/feedback'
		},
	])
	const tologin = ()=>{
		uni.navigateTo({
			url:"/subpages/login/login"
		})
	}
	const user = ref({})
	const getUserInfo = async ()=>{
		const res = await  getUserInfoAPI()
		user.value = res.user
		uni.setStorageSync('user',res.user)
		console.log(user.value);
	}
	const laout = ()=>{
		uni.removeStorageSync('token')
		user.value ={}
	}
	
	onShow(()=>{
		if(uni.getStorageSync('token')){
			getUserInfo()
		}
	})
</script>

<style>

</style>
